package com.hub.videobrowsdownload;

import android.util.Log;
import android.webkit.JavascriptInterface;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class BrowsJavsscripShowVideo {

    private BrowsTabWebViewModel tabWebViewModel;
    public BrowsJavsscripShowVideo(BrowsTabWebViewModel viewModel){
        tabWebViewModel = viewModel;
    }
    @JavascriptInterface
    public void showVideoHTML(String[] arr_s) {
        if (arr_s.length == 0) {
            return;
        }
        StringBuilder stringBuilder0 = new StringBuilder("<html>");
        for(int v = 0; v < arr_s.length; ++v) {
            stringBuilder0.append(arr_s[v]);
        }

        stringBuilder0.append("</html>");

        String htmlCode = stringBuilder0.toString();
        // 解析HTML代码
        Document doc = Jsoup.parse(htmlCode);
        // 选择所有的video标签
        Elements videoTags = doc.select("video");

        // 遍历每个video标签
        for (Element videoTag : videoTags) {
            // 提取src属性的值
            String srcValue = videoTag.attr("src");
            Log.i("视频地址：", "src: " + srcValue);
            tabWebViewModel.findVideoSrc(srcValue);
        }
    }
}
